package com.liuzu.esys.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.liuzu.esys.common.LayuiPageVo;
import com.liuzu.esys.mapper.FinUserMapper;
import com.liuzu.esys.pojo.FinUser;
import com.liuzu.esys.service.FinUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;
import java.util.Map;

/**
 * @author : 松松
 * @date : 2022/7/26
 * @desc :
 */

@Service("fuService")
public class FinUserServiceImpl implements FinUserService {

    @Autowired
    private FinUserMapper finUserMapper;


    //查询
    @Override
    public LayuiPageVo<FinUser> fuList(@RequestParam Map<String, Object> params) {
        //mybatis 的 分页查询
        Integer page = Integer.parseInt(params.get("page") + "");
        Integer limit = Integer.parseInt(params.get("limit") + "");
        PageHelper.startPage(page, limit);

        List<FinUser> fuList = finUserMapper.selectByEample(params);

        //mybatis 的 分页数据结构
        PageInfo<FinUser> finUserPageInfo = new PageInfo<>(fuList);
        //把 mybatis 的分页数据封装到 layui的分页数据结构中
        LayuiPageVo<FinUser> finUserLayuiPageVo = new LayuiPageVo<>();
        finUserLayuiPageVo.setCode(0);  // layui 默认 0 是正确的状态码
        finUserLayuiPageVo.setMsg("分页列表数据"); // 提示信息
        finUserLayuiPageVo.setCount((long) finUserPageInfo.getTotal()); // 总记录数
        finUserLayuiPageVo.setData(finUserPageInfo.getList());  // 分页的列表数据
        return finUserLayuiPageVo;
    }


    //添加
    @Override
    public int addfu(FinUser finUser) {
        return finUserMapper.addfu(finUser);
    }


    //删除
    @Override
    public int delfu(Integer id) {
        return finUserMapper.delfu(id);
    }


    //修改
    @Override
    public int setfu(FinUser finUser) {
        return finUserMapper.setfu(finUser);
    }
}
